"""
    Windows Package Manager
"""

import sys,getopt

optr=["help", "install=", "upgrade", "update", "search=", "y"]
optl=["--help", "--install", "--upgrade", "--update", "--search", "--y"]

opts, args=getopt.getopt(sys.argv[1:], "hu", optr)

__version__="1.0"

import download 
import install 
import search 
import update 

_in_dow=lambda x:0
_in_ins=lambda x:0
_in_sea=lambda x:0
_in_upg=lambda x:0
_in_upd=lambda x:0
_in_sea=lambda x:0

_help=f"""Windows Package Manager ({__version__}) Help Information
Options:
    --help
    --install <package ...>
    --search <keyword>
    --update
    --upgrade
This Windows software manager is super confusing"""

def _in_help():
    global _help
    sys.stderr.write(_help+"\n")
    return 1

cmdlist={
        "--download": _in_dow,
        "--install": _in_ins,
        "--upgrade": _in_upg,
        "--update": _in_upd,
        "--search": _in_sea,
        "--help": _in_help
        }

def main():
    global opts, args
    if opts==[] and args==[]:
        sys.exit(_in_help())
    for i in opts:
        if i[0] in optl:
            return cmdlist[i[0]](i[1])
        else:
            sys.stderr.write(f"winpm: \033[91mfatal error\033[0m: Unrecognized option: {i[0]}\n{_help}\n")
            return 1

if __name__=="__main__":
    sys.exit(main())

